package asia.yuanding.wechat.system.advice;

import asia.yuanding.wechat.system.exception.BusinessException;
import asia.yuanding.wechat.system.util.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.Arrays;

/**
 * @ClassName: BusinessConllerAdvice
 * @Author: YuanDing
 * @Date: 2025/7/27 9:20
 * @Description:
 * 通用业务异常处理
 */

@Slf4j
@RestControllerAdvice
public class BusinessControllerAdvice {


    @ExceptionHandler(BusinessException.class)
    public R handleBusinessException(BusinessException e) {
        return R.fail(e.getCode() , e.getMessage());
    }


    @ExceptionHandler(Exception.class)
    public R handleException(Exception e) {
        log.error( "系统异常：",e);
        return R.fail("系统异常，请稍后重试");
    }
}
